#ifndef MY_MOUSE_H
#define MY_MOUSE_H

#ifndef HEAD_Q_H
#include "../head_Q.h"
#endif

#ifndef FACILITY_DEFINE_H
#include "../Facility/Facility_Define.h"
#endif

#ifndef OBJECT_QT_H
#endif
#include <QDebug>
#include <QPixmap>

/// 我的鼠标类
class My_Mouse{
public:
    FacilityType f_type;
    FacilityDirection f_dir;
    int groupNum;
    int groupIdx;
    QPixmap mouse_pix;
    My_Mouse(int groupNum = 1);
    // 选择设备
    inline void chooseFacility(FacilityType f_t, int groupNum, int groupIdx = 0){

        if(f_t == this->f_type){clear(); return;} // 如果相同就是取消选择
        this->f_type = f_t;
        this->groupIdx = groupIdx;
        this->groupNum = groupNum;
        QString imgPath = findImgPathFromTypeANDIdx();
        qDebug() << "Your choice:"+imgPath;
        QImage image(imgPath);
        this->mouse_pix = QPixmap::fromImage(image.scaled(image.width()*15.0/16,image.height()*15.0/16));

    }
    // 默认顺时针旋转
    inline void changeDir(){
        if(f_type == FacilityType::TRASH){return;}
        f_dir = (FacilityDirection)((f_dir+1)%4);
        mouse_pix = mouse_pix.transformed(QTransform().rotate(90));
    }
    // 更改idx idx为更改后的idx
    inline void changeIdx(){
        f_dir = Facility_UP; // !!!
        if(groupNum == 1){groupIdx = 0;}
        this->groupIdx = (this->groupIdx + 1) % this->groupNum;
        QImage image(findImgPathFromTypeANDIdx());
        this->mouse_pix = QPixmap::fromImage(image.scaled(image.width()*15.0/16,image.height()*15.0/16));
    }
    // 是否是空
    inline bool isempty(){return(f_type == FacilityType::Facility_NONE &&
                                    f_dir == FacilityDirection::Facility_UP &&
                                    groupIdx == 0 );}
    // 清空
    inline void clear(){
        f_type = FacilityType::Facility_NONE;
        f_dir = FacilityDirection::Facility_UP;
        groupIdx = 0;
        groupNum = 1;
    }
    // 寻找 地址
    inline QString findImgPathFromTypeANDIdx(){
        QString res = QString::fromStdString(FacilityDefine::fromTypeAndIdxToString(f_type,groupIdx));
        return QString("%1/%2.png").arg(BUILDING_IMG_SRC).arg(res);
    }
};


#endif
